{% extends 'base.html' %}

{% block head %}

{% endblock %}

{% block title %}
登陆页面
{% endblock %}

{% block body %}
{% if form.errors %}
    {% for field_name, field_errors in form.errors|dictsort if field_errors %}
        {% for error in field_errors %}
            <div class="alert alert-warning" role="alert">
                <p align="center" style="color:red;">{{ error }}</p>
            </div>
        {% endfor %}
    {% endfor %}
{% endif %}
    <div class="login" style="width:350px;margin: 0 auto;margin-top: 50px;">
        <h2>登陆</h2>
        <hr>
        <form class="layui-form" action="{{ url_for('app.login') }}" method="post">
            {{ form.hidden_tag() }}
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                <input type="email" name="email" required  lay-verify="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                <input type="password" name="password" required lay-verify="pwd" placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">记住密码</label>
                <div class="layui-input-block">
                <input type="checkbox" name="switch" lay-skin="switch" lay-text="ON|OFF" checked>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即登陆</button>
                <a href="{{ url_for('app.regist') }}" class="layui-btn layui-btn-primary">前往注册</a>
                </div>
            </div>
        </form>
    </div>



    <script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            {#layer.msg(JSON.stringify(data.field));#}
            return true;
        });
        form.verify({
            email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对'],
            pwd: [/(.+){6,12}$/, '密码必须6到12位']
        });
        form.render();
    });
    </script>
{% endblock %}